#include <iostream>
#include <fstream>
#include <vector>
#include <climits>

using namespace std;

const int MAXN = 100010;
const long long MAXCOST = LLONG_MAX;  // 改为使用LLONG_MAX

int n;
vector<int> w(MAXN), dist(MAXN);
vector<long long> prefix_w(MAXN), prefix_wd(MAXN);
long long tot;
long long mincost;

void readin() {
    ifstream fin("input.txt");
    if (!fin.is_open()) {
        cerr << "Error opening input.txt" << endl;
        exit(1);
    }
    
    fin >> n;
    if (n < 1 || n >= MAXN) {
        cerr << "Invalid n value: " << n << endl;
        exit(1);
    }
    
    dist[1] = 0;
    fin >> w[1] >> dist[2];
    prefix_w[1] = w[1];
    prefix_wd[1] = 0;
    tot = w[1] * dist[2];
    
    for (int i = 2; i <= n; i++) {
        int d;
        fin >> w[i] >> d;
        prefix_w[i] = prefix_w[i-1] + w[i];
        dist[i+1] = dist[i] + d;
        prefix_wd[i] = prefix_wd[i-1] + w[i] * dist[i];
        tot += w[i] * dist[i+1];
    }
    fin.close();
}

long long getcost(int i, int j) {
    if (i > j) return MAXCOST;  // 无效情况返回最大值
    return tot - (prefix_w[i] * dist[i]) - (prefix_w[j] - prefix_w[i]) * dist[j] 
           - (prefix_w[n] - prefix_w[j]) * dist[n+1] + prefix_wd[i] + (prefix_wd[j] - prefix_wd[i]);
}

void comp(int minp1, int maxp1, int minp2, int maxp2) {
    if (minp1 >= minp2) minp2 = minp1 + 1;
    if (maxp1 >= maxp2) maxp1 = maxp2 - 1;
    if ((minp1 > maxp1) || (minp2 > maxp2)) return;
    
    int j = (minp2 + maxp2) / 2;
    int opt = minp1;
    long long optcost = MAXCOST;
    
    for (int i = minp1; i <= min(maxp1, j-1); i++) {
        long long cost = getcost(i, j);
        if (cost < optcost) {
            opt = i;
            optcost = cost;
        }
    }
    
    if (optcost < mincost) mincost = optcost;
    
    comp(minp1, opt, minp2, (minp2 + maxp2) / 2 - 1);
    comp(opt, maxp1, (minp2 + maxp2) / 2 + 1, maxp2);
}

int main() {
    readin();
    mincost = MAXCOST;
    comp(1, n-1, 2, n);
    
    ofstream fout("output.txt");
    if (!fout.is_open()) {
        cerr << "Error opening output.txt" << endl;
        return 1;
    }
    fout << mincost << endl;
    fout.close();
    
    cout << "Minimum cost: " << mincost << endl;
    return 0;
}
